class Solution(object):
    def nextGreaterElement(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        d = {}
        stack = [nums2[0]]
        for i in range(1, len(nums2)):
            while stack and nums2[i] > stack[-1]:
                d[stack[-1]] = nums2[i]
                stack.pop()
            stack.append(nums2[i])
        for i in range(len(nums1)):
            if nums1[i] in d:
                nums1[i] = d[nums1[i]]
            else:
                nums1[i] = -1
        return nums1
